import { defineStore } from "pinia";

export const useHeaderSettingStore = defineStore("header-setting", {
  state: () => ({
    fold: false,
    dark: false,
    headerBackground:false,
    headerBreadCrumb:false,
    isChangeThemeList:''
  }),
  persist: true,//开启持久化存储的配置
  actions: {
    ChangeThemeList(item:string){
      this.isChangeThemeList = item
    },
    onResetStatus(){
      this.dark = false
      this.headerBackground = false
      this.headerBreadCrumb = false
      this.isChangeThemeList = ''
      localStorage.removeItem('headerBackground')
      localStorage.removeItem('dark')
      localStorage.removeItem('breadCrumb')
      localStorage.removeItem('ThemeList')
      window.location.reload();
    },
    // 将导航头背景颜色保存到本地，使用 'true'/'false' 字符串
    setHeaderBgcStatue(){
      localStorage.setItem("headerBackground", this.headerBackground ? "true" : "false");
    },
    // 将黑夜模式保存到本地，使用 'true'/'false' 字符串
    saveDarkStatue() {
      localStorage.setItem("dark", this.dark ? "true" : "false");
    },
    // 将面包屑状态保存到本地，使用 'true'/'false' 字符串
    saveBreadCrumbStatue() {
      localStorage.setItem("breadCrumb", this.headerBreadCrumb ? "true" : "false");
    },
    // 将主题保存到本地
    saveThemeListStatue() {
      localStorage.setItem("ThemeList", this.isChangeThemeList);
    },

    // 从 localStorage 中读取 dark 的 "boolean值" 并转换为 boolean
    getDarkStatue() {
      this.dark = localStorage.getItem("dark") === "true"
      return localStorage.getItem("dark") === "true";
    },
    // 从 localStorage 中读取 headerBackground 的 "boolean值" 并转换为 boolean
    getHeaderBgcStatue() {
      this.headerBackground = localStorage.getItem("headerBackground") === "true"
      return localStorage.getItem("headerBackground") === "true";
    },
    // 从 localStorage 中读取 BreadCrumbStatue 的 "boolean值" 并转换为 boolean
    getBreadCrumbStatue() {
      this.headerBreadCrumb = localStorage.getItem("breadCrumb") === "true"
      return localStorage.getItem("breadCrumb") === "true";
    },
    // 从 localStorage 中读取 BreadCrumbStatue 的 "boolean值" 并转换为 boolean
    getThemeListStatue() {
      this.isChangeThemeList = localStorage.getItem("ThemeList") as string
      return localStorage.getItem("ThemeList")
    },
  },
});
